package dataMapper;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import dataEntity.RiskFactorsAndAccessToCare;

public class RiskFactorsAndAccessToCareMapper {
	public static  Map<String,Map<String,RiskFactorsAndAccessToCare>> process(BufferedReader br){
		Map<String,Map<String,RiskFactorsAndAccessToCare>> map = new HashMap<String,Map<String,RiskFactorsAndAccessToCare>> ();
		try {
			br.readLine();
			while(br.ready()){
				RiskFactorsAndAccessToCare object = buildObject(br.readLine());

				Map<String,RiskFactorsAndAccessToCare> stateMap = map.get(object.getCHSI_State_Abbr());
				if(stateMap == null) stateMap = new HashMap<String,RiskFactorsAndAccessToCare>();
				stateMap.put(object.getCHSI_County_Name(), object);
				map.put(object.getCHSI_State_Abbr(), stateMap);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return map;
	}
	
	public static  RiskFactorsAndAccessToCare buildObject(String inLine){
		String[] line = inLine.split(",");
		RiskFactorsAndAccessToCare object = new RiskFactorsAndAccessToCare();
		
		object.setState_FIPS_Code(line[0]);
		object.setCounty_FIPS_Code(line[1]);
		object.setCHSI_County_Name(line[2]);
		object.setCHSI_State_Name(line[3]);
		object.setCHSI_State_Abbr(line[4]);
		object.setStrata_ID_Number(line[5]);
		object.setNo_Exercise(line[6]);
		object.setCI_Min_No_Exercise(line[7]);
		object.setCI_Max_No_Exercise(line[8]);
		object.setFew_Fruit_Veg(line[9]);
		object.setCI_Min_Fruit_Veg(line[10]);
		object.setCI_Max_Fruit_Veg(line[11]);
		object.setObesity(line[12]);
		object.setCI_Min_Obesity(line[13]);
		object.setCI_Max_Obesity(line[14]);
		object.setHigh_Blood_Pres(line[15]);
		object.setCI_Min_High_Blood_Pres(line[16]);
		object.setCI_Max_High_Blood_Pres(line[17]);
		object.setSmoker(line[18]);
		object.setCI_Min_Smoker(line[19]);
		object.setCI_Max_Smoker(line[20]);
		object.setDiabetes(line[21]);
		object.setCI_Min_Diabetes(line[22]);
		object.setCI_Max_Diabetes(line[23]);
		object.setUninsured(line[24]);
		object.setElderly_Medicare(line[25]);
		object.setDisabled_Medicare(line[26]);
		object.setPrim_Care_Phys_Rate(line[27]);
		object.setDentist_Rate(line[28]);
		object.setCommunity_Health_Center_Ind(line[29]);
		object.setHPSA_Ind(line[30]);

		return object;
	}
}
